<?php

/**
 * evenement actions.
 *
 * @package    e-DSL
 * @subpackage actions
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class evenementActions extends sfActions
{
	function getClassName($request)
	{  	
		return 'evenement';
	}
	
	function getModuleName()
	{
		return 'defaultViewer';
	}

	public function executeGetList(sfWebRequest $request){
		$ownerclass = $request->getParameter('ownerclass');
		$owner_id  = $request->getParameter('owner_id');
		$objectDef = new objectDef('evenement');
		$q = $objectDef->getBaseQuery();
		$q->addWhere('a.ownerclass= ? ', $ownerclass );
		$q->addWhere('a.owner_id= ?', $owner_id);
		$q->setHydrationMode(Doctrine_Core::HYDRATE_ARRAY);
		$items =	$q->execute();
		$this->renderPartial('ajaxViewer/list', array('self'=>$self, 'className' => 'evenement', 'items'=>$items, 'objectDef'=>$objectDef));
		
	}
	
	public function executeNew(sfWebRequest $request)
	{
		$formClass = $this->getClassName($request).'Form';
		$this->form = new $formClass();
		$id = $request->getParameter('id');
		$ownerclass = $request->getParameter('classname');
		$this->form->setDefault('owner_id', $id);
		$this->form->setDefault('ownerclass', $ownerclass);
		
		
		$this->personne=$this->getUser()->getUserProfile();
		$this->form->setDefault('personne_id', $this->personne->id);
			
    	if(!$this->personne->estInterne())
    	{
    			$this->form->hideWidget('public');
    			$this->hide = array('public');
    			$this->form->setDefault('public', true);
    	}
		$this->getUser()->setAttribute('ownerId',$id);
	    $this->getUser()->setAttribute('ownerClass',$ownerclass);
		if($ownerclass=='client'){
	    	$this->getUser()->setAttribute('ownerModule','clients');
	    }elseif($ownerclass=='dossier'){
	    	$this->getUser()->setAttribute('ownerModule','mesdossiers');
	    }
	    $this->className = $this->getClassName($request);
		$this->module = $this->getModuleName();
		$this->objDef = new objectDef($this->className);
	  	if($this->objDef->hasAttach){
			$this->formAttach = new attachmentForm();
			$this->getUser()->setAttribute('filesToUpload', array());
		}
	}
}